﻿using FigureDraw.Diagram;
using FigureDraw.Graphic;
using FigureDraw.Shapes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FigureDraw
{
    public partial class FigureDraw : Form
    {
        MyPicture picture;
        CommonGraphic graphic;
        BlockDiagram diagram;

        public FigureDraw()
        {
            InitializeComponent();
        }

        private void FigureDraw_Load(object sender, EventArgs e)
        {
            diagram = new ActivityDiagram();
            

            picture = new MyPicture();
            //picture.Add(new MyLine(40, 40, 220, 120));
            //picture.Add(new MyRectangle(40, 40, 180, 80));
            //picture.Add(new MyEllipse(40, 40, 180, 80));
            //picture.Add(new MyStar(40, 40, 180, 80));
            //picture.Add(new MyFlower(40, 40, 180, 80));

            //picture.Add(diagram.DrawBegin(0, 0, 200, 100));
            //picture.Add(diagram.DrawInput(0, 0, 200, 100));
            //picture.Add(diagram.DrawProcess(0, 0, 200, 100));
            //picture.Add(diagram.DrawOutput(0, 0, 200, 100));
            //picture.Add(diagram.DrawMove(0, 0, 200, 100));
            //picture.Add(diagram.DrawCondition(0, 0, 200, 100));
            //picture.Add(diagram.DrawEnd(0, 0, 200, 100));
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Draw();
        }

        private void rbCairo_CheckedChanged(object sender, EventArgs e)
        {
            Draw();
        }

        private void rbGDIPlus_CheckedChanged(object sender, EventArgs e)
        {
            Draw();
        }

        private void Draw()
        {
            pDraw.Invalidate();
            pDraw.Refresh();

            if (UpdateGraphic())
                picture.Draw(graphic);
        }

        private bool UpdateGraphic()
        {
            if (rbCairo.Checked)
                //graphic = new CairoPNGGraphic("D:/cairoPNGMydraw.png");
                //graphic = new CairoSVGGraphic("D:/cairoPNGMydraw.svg");
                graphic = new CairoScreenGraphic(pDraw.CreateGraphics());
            else if (rbGDIPlus.Checked)
                //graphic = new GDIPlusSVGGraphic("D:/mydrawSVG.svg");
                //graphic = new GDIPlusPNGGraphic("D:/mydraw.png");
                graphic = new GDIPlusScreenGraphic(pDraw.CreateGraphics());
            else
                return false;

            return true;
        }


    }
}
